package com.shockweb.common.calculate.function;

import com.shockweb.common.calculate.CalculateException;
import com.shockweb.common.calculate.api.IFunction;

import java.util.List;

/**
 * 字符串两头去空白字符
 * @author pengminghua
 *
 */
public class Trim implements IFunction{
	
	/**
	 * @see IFunction#eval(List)
	 */
	public String eval(List<Object> params) throws CalculateException {
		try{
			Object value = params.get(0);
			if(value==null){
				throw new NullPointerException();
			}else{
				return ((String)value).trim();
			}
		}catch(Exception e){
			throw new CalculateException(e);
		}
	}


	/**
	 * @see IFunction#getParamCount()
	 */
	public int getParamCount() {
		return 1;
	}
	
	/**
	 * @see IFunction#getName()
	 */
	public String getName() {
		return "trim";
	}
}
